//
//  OrderMainVC.m
//  代理端
//
//  Created by sliver on 15/12/14.
//  Copyright (c) 2015年 sliver. All rights reserved.
//

#import "OrderMainVC.h"
#import "Unit.h"
#import "OrderDetailsVC.h"
#import "ReturnGoodsVC.h"
#import "LogisticsVC.h"
#import "BalanceVC.h"
#import "StockVC.h"
#import "ApplyVC.h"
#import "AboutOurVC.h"
#import "ShoppingMainVC.h"
#import "HeadVC.h"
#import "AgentVC.h"
#import "WXDataService.h"
#import "UIImageView+WebCache.h"
#import "PullTableView.h"
#import "SBJson.h"
#import "OrderModel.h"
#import "productCell.h"

typedef NS_ENUM(NSUInteger, cellTypeselectde) {
    cellTypeselectdeWaitPost,
    cellTypeselectdeWaitHandle,
    cellTypeselectdeNoraml,
};


@interface OrderMainVC ()<UITableViewDataSource,UITableViewDelegate,PullTableViewDelegate,BackViewDeleget,productCellDeleget,OrderDetailsVCDeleget>
{
    UIView *mainView; //主页view
    UIView *menuview; //菜单页
    
    PullTableView *maintableview;
    
    UIAlertView *confirmalert;
    UIAlertView *deletealert;
    
    NSInteger deleBtnPath;
    int page; //下拉刷新
    cellTypeselectde celltype;
    
}
@property(nonatomic,strong)UIImageView *imageview;
@property(nonatomic,strong)UIButton *chongxinjaizai;
@property(nonatomic,strong)OrderModel *ormodel;
@property(nonatomic,strong)NSMutableArray *wuliuarray;
@property(nonatomic,strong)UIButton *butten;
@property(nonatomic,strong)UIView *baview;
@end

@implementation OrderMainVC
-(UIView *)baview
{

    if (!_baview) {
        _baview = [[UIView alloc]initWithFrame:CGRectMake(0, 100*KScr, ScreenW, ScreenH-100*KScr)];
        
        [_baview addSubview:self.imageview];
        
        _baview.hidden = YES;
    }

    return _baview;
}
-(UIButton *)chongxinjaizai
{
    if (!_chongxinjaizai) {
        _chongxinjaizai = [[UIButton alloc]initWithFrame:CGRectMake(10*KScr, 148*KScr, 148*KScr, 40*KScr)];
        
        [_chongxinjaizai addTarget:self action:@selector(chongxinjiazaide) forControlEvents:UIControlEventTouchUpInside];
    }
    return _chongxinjaizai;

}
-(UIImageView *)imageview
{
    if (!_imageview) {
        _imageview= [[UIImageView alloc]initWithFrame:CGRectMake(100*KScr , 100*KScr, 168*KScr,188*KScr)];
        _imageview.image = [UIImage imageNamed:@"kongwei.png"];
        _imageview.userInteractionEnabled = YES;
        [_imageview addSubview:self.chongxinjaizai];
    }
    return _imageview;
}
-(NSMutableArray *)wuliuarray
{
    if (!_wuliuarray) {
        _wuliuarray = [NSMutableArray array];
    }
    return _wuliuarray;
}
-(NSMutableArray *)dataAry
{
    if (!_dataAry) {
        _dataAry=[NSMutableArray array];
    }

    return _dataAry;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    page = 1;
    [self loadmenuView];
    [self loadNav];
    [self loadmainView];
    [self loaddata:@"-1" andPage:@"1"withClic:YES];
}
-(void)loadmainView{
    _state = @"-1";
    NSArray *btnAry = @[@"全部",@"待发货",@"待收货",@"已收货",@"退货"];
    for (int i=0;i<5;i++){
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(i*ScreenW/5, 61, ScreenW/5, 40)];
        btn.tag = i+10;
        [btn setTitle:[btnAry objectAtIndex:i] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor whiteColor];
        if(i == 0){
            btn.backgroundColor = DRINK_RED_COLOR;
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
        [btn addTarget:self action:@selector(clickbtn:)forControlEvents:UIControlEventTouchUpInside];
        [mainView addSubview:btn];
    }
    
    maintableview = [[PullTableView alloc]initWithFrame:CGRectMake(0, 102, ScreenW, ScreenH - 102) style:UITableViewStylePlain];
    maintableview.delegate = self;
    maintableview.dataSource = self;
    maintableview.pullDelegate = self;
    maintableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    maintableview.tableFooterView = [[UITableView alloc]init];
    [mainView addSubview:maintableview];
    [mainView addSubview:self.baview];
}
#pragma mark - 点击btn
-(void)clickbtn:(UIButton *)sender{
    self.butten = sender;
    self.isPull = NO;
    for(int i=1;i<=5;i++){
        UIButton *btn = (UIButton *)[self.view viewWithTag:i+9];
        btn.backgroundColor = [UIColor whiteColor];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    sender.backgroundColor = DRINK_RED_COLOR;
    [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    switch (sender.tag) {
        case 10:
            _state = @"-1";
            break;
        case 11:
            _state = @"11";
            break;
        case 12:
            _state = @"13";
            break;
        case 13:
            _state = @"14";
            break;
        case 14:
            _state = @"15";
            break;
        default:
            break;
    }
    [self loaddata:_state andPage:@"1" withClic:YES];
    
}
-(void)chongxinjiazaide
{
    [self clickbtn:self.butten];

}
#pragma mark - 发送请求
-(void)loaddata:(NSString *)state andPage:(NSString *)pages withClic:(BOOL)btnClic{
    if (btnClic) {
        [MyMbd addHudToView:self.view];
    }
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
//    if ([state intValue] == 11) {
//        [params setObject:@"3" forKey:@"state_step"];
//    }else if([state intValue] == 13){
//        [params setObject:@"0" forKey:@"state_step"];
//    }
    
    [params setObject:USER_ACCOUNT forKey:@"agency_id_"];
    [params setObject:state forKey:@"state"];
    [params setObject:pages forKey:@"page"];
    [WXDataService requestWithURL:@"mobile/agency/listAgencyOrderPage.jhtml" params:params httpMethod:@"POST" block:^(id result, NSString *success, NSString *msg) {
        NSLog(@"%@",result);
        if (btnClic) {
            [MyMbd hidenHudFromView:self.view];
        }
        BOOL suc =[success boolValue];
        if (suc == 0 ) {
            UIAlertView *deleAlertView=[[UIAlertView alloc]initWithTitle:nil message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [deleAlertView show];
            return;
        }else if(suc == 1){
            
            NSLog(@"%@",result);
            
            [self.dataAry removeAllObjects];
            
            
            NSDictionary *dic =[result objectForKey:@"order"];
            NSArray *array = [dic objectForKey:@"listItems"];
            
            for (NSDictionary *dic2 in array) {
                OrderModel *model = [[OrderModel alloc]initWithDataDic:dic2];
                
                
                [self.dataAry addObject:model];
                
            }
            if (self.dataAry.count ==0) {
                self.baview.hidden = NO;
            }else
            {
                self.baview.hidden = YES;
            }
            
            
            [maintableview reloadData];
        }

}failblock:^(AFHTTPRequestOperation *operation, NSError *error) {
    if (btnClic) {
        [MyMbd hidenHudFromView:self.view];

    }
    }];
    
    self.isPull = YES;
}
#pragma mark - 发送请求下拉用
-(void)loaddata2:(NSString *)state andPage:(NSString *)pages{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    if ([state intValue] == 11) {
        [params setObject:@"3" forKey:@"state_step"];
    }else if([state intValue] == 13){
        [params setObject:@"0" forKey:@"state_step"];
    }
    [params setObject:USER_ACCOUNT forKey:@"agency_id_"];
    [params setObject:state forKey:@"state"];
    [params setObject:pages forKey:@"page"];
    [WXDataService requestWithURL:@"mobile/agency/listAgencyOrderPage.jhtml" params:params httpMethod:@"POST" block:^(id result, NSString *success, NSString *msg) {
        BOOL suc =[success boolValue];
        if (suc == 0 ) {
            UIAlertView *deleAlertView=[[UIAlertView alloc]initWithTitle:nil message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [deleAlertView show];
            return;
        }else if(suc == 1){
            NSDictionary *dic =[result objectForKey:@"order"];
            NSArray *array = [dic objectForKey:@"listItems"];
            
            for (NSDictionary *dic2 in array) {
                OrderModel *model = [[OrderModel alloc]initWithDataDic:dic2];
                
                
                [self.dataAry addObject:model];
                
            }
            [maintableview reloadData];
        }
    }failblock:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

#pragma mark - nav
-(void)loadNav{
    mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH)];
    mainView.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    [self.view addSubview:mainView];
    UIView *redview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    redview.backgroundColor = DRINK_RED_COLOR;
    [mainView addSubview:redview];
    
    UILabel *redLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenW, 40)];
    redLab.backgroundColor = DRINK_RED_COLOR;
    redLab.text = @"订单";
    redLab.textColor = [UIColor whiteColor];
    redLab.textAlignment =  NSTextAlignmentCenter;
    redLab.font = [UIFont boldSystemFontOfSize:17];
    [mainView addSubview:redLab];
    
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 20,44, 40)];
    backBtn.adjustsImageWhenHighlighted = NO;
    [backBtn setImage:[UIImage imageNamed:@"菜单"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(clickBack:) forControlEvents:UIControlEventTouchUpInside];
    [mainView addSubview:backBtn];
}
#pragma mark - 菜单页
-(void)loadmenuView{
    menuview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenW *0.75, ScreenH)];
    menuview.backgroundColor = DRINK_LIGHTGRAY_COLOR;
    for(int i=1;i<9;i++){
        NSArray *menuAry = @[@"    首页",@"    商城",@"    订单",@"    余额",@"    库存",@"    申请返利",@"    关于我们",@"    退出"];
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 100+41*i, ScreenW *0.75, 40)];
        btn.tag = i;
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        btn.backgroundColor = [UIColor whiteColor];
        [btn setTitle:[menuAry objectAtIndex:i-1] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickmenu:) forControlEvents:UIControlEventTouchUpInside];
        [menuview addSubview:btn];
    }
    //上面头像等
    UIImageView*imageview = [[UIImageView alloc]init];
    imageview.backgroundColor = [UIColor whiteColor];
    NSString *string =  [NSString stringWithFormat:@"%@%@",BASE_URL,USER_IMG];
    NSURL *imgurl = [NSURL URLWithString:string];
    [imageview setImageWithURL:imgurl placeholderImage:[UIImage imageNamed:@"代理商信息头像_150.png"]] ;
    imageview.frame =CGRectMake(20, 40, 80, 80);
    imageview.layer.masksToBounds = YES;
    imageview.layer.cornerRadius = 5;
    imageview.userInteractionEnabled = YES;
    //单击手势
    UITapGestureRecognizer *sigleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(signalTapAction)];
    [imageview addGestureRecognizer:sigleTap];
    [menuview addSubview:imageview];
    //名称
    UILabel *nameLab = [[UILabel alloc]initWithFrame:CGRectMake(120, 40, ScreenW *0.75 - 120, 20)];
    nameLab.text = CPOMANY_NAME;
    nameLab.font = [UIFont systemFontOfSize:15];
    [menuview addSubview:nameLab];
    //等级
    UILabel *levelLab = [[UILabel alloc]initWithFrame:CGRectMake(120, 65, ScreenW *0.75 - 120, 20)];
    levelLab.font = [UIFont systemFontOfSize:15];
    switch ([USER_LEVEL integerValue]) {
        case 1:
            levelLab.text =@"省级代理";
            break;
        case 2:
            levelLab.text =@"市级代理";
            break;
        case 3:
            levelLab.text =@"县级代理";
            break;
        case 4:
            levelLab.text =@"采集代理";
            break;
            
        default:
            break;
    }
    [menuview addSubview:levelLab];
    
    //中间竖线
    UIView *vieww = [[UIView alloc]initWithFrame:CGRectMake(ScreenW *0.75-1, 0, 1, ScreenH)];
    vieww.backgroundColor = [UIColor blackColor];
    vieww.layer.shadowColor = [[UIColor blackColor]CGColor];
    vieww.layer.shadowRadius = 3;
    vieww.layer.shadowOpacity = 0.9;
    vieww.layer.shadowOffset = CGSizeMake(-3, 0);
    [menuview addSubview:vieww];
    [self.view addSubview:menuview];
}
#pragma mark - 点击菜单
-(void)clickmenu:(UIButton *)sender{
    NSArray *array = @[@"HeadVC",@"ShoppingMainVC",@"OrderMainVC",@"BalanceVC",@"StockVC",@"ApplyVC",@"AboutOurVC",@"LandingVC"];
    if (sender.tag<9) {
        NSDictionary *dic = [NSDictionary dictionary];
        dic = @{@"vc":array[sender.tag-1]};
        
        NSLog(@"%@",dic);
        
        if (sender.tag-1==0) {
            [self dismissViewControllerAnimated:NO completion:^{}];
            
        }else
        {
            if (sender.tag == 8) {
                [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"tuichudenglu"];
            }
            [self dismissViewControllerAnimated:NO completion:^{}];
            [[NSNotificationCenter defaultCenter]postNotificationName:@"ceshi" object:self userInfo:dic];
            
            
        }

    }else
    {
        AppDelegate *dele = (AppDelegate *)[[UIApplication sharedApplication]delegate] ;
        NSUserDefaults *userDefaultes = [NSUserDefaults standardUserDefaults];
        [userDefaultes setObject: nil forKey:@"USER_ID"];
        [userDefaultes setObject:nil forKey:@"USER_PWD"];
        [userDefaultes setObject:nil forKey:@"USER_IMG"];
        [userDefaultes setObject:nil forKey:@"USER_LEVEL"];
        [userDefaultes setObject:nil forKey:@"USER_ACCOUNT"];
        [userDefaultes setObject:nil forKey:@"USER_DIC"];
        [userDefaultes setObject:nil forKey:@"CPOMANY_NAME"];
        [userDefaultes synchronize];
        [dele showMain];
}
}
-(void)viewTapAction{
    [UIView animateWithDuration:0.2 animations:^(){
        mainView.frame = CGRectMake(0, 0, ScreenW, ScreenH);
    }];
}
#pragma mark - 菜单按钮
-(void)clickBack:(UIButton *)sender{
    sender.selected = !sender.selected;
    if(sender.selected){
        [UIView animateWithDuration:0.2 animations:^(){
            mainView.frame = CGRectMake(ScreenW*0.75, 0, ScreenW, ScreenH);
        }];
        
        UIView *shoushiView = [[UIView alloc]initWithFrame:CGRectMake(ScreenW*0.75, 0, ScreenW*0.25, ScreenH)];
        shoushiView.tag = 1999;
        shoushiView.userInteractionEnabled = YES;
        shoushiView.backgroundColor = [UIColor clearColor];
        [self.view addSubview:shoushiView];
        //单击手势
        UITapGestureRecognizer *sigleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(viewTapAction)];
        //设置点击手指的根数
        sigleTap.numberOfTouchesRequired = 1;
        //点击屏幕次数
        sigleTap.numberOfTapsRequired = 1;
        [shoushiView addGestureRecognizer:sigleTap];
        
        
    }else{
        UIView *view = (UIView *)[self.view viewWithTag:1999];
        [view removeFromSuperview];
        [UIView animateWithDuration:0.2 animations:^(){
            mainView.frame = CGRectMake(0, 0, ScreenW, ScreenH);
        }];
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataAry.count;
}
-(productCell *)tableview:(UITableView *)tableview DequWith:(NSString *)reuseIdentifier Withmodel:(OrderModel *)model
{
    productCell *cell = [tableview dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
                
//        cell = [[OrderTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        cell = (productCell *)[productCell creatCellFromxib:@"productCell" WithIdentifier:reuseIdentifier withtableview:tableview];
    }
    cell.block=^(OrderModel *model)
    {
        [BackView addToview:self.view WithDeleget:self WithMessage:@"是否取消订单?" WithBtnCount:2];
        self.ormodel = model;
    };
    cell.deleget = self;
    return cell;

}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    OrderModel *model = self.dataAry[indexPath.row];
    
    productCell *cell = [self tableview:tableView DequWith:@"cellone" Withmodel:model];

    [cell gaveMeMode:model Withindex:indexPath.row];
    return cell;
    
}
#pragma mark---productdeleget
//确认收货
-(void)masureGetProduct:(OrderModel *)model
{
    [BackView addToview:self.view WithDeleget:self WithMessage:@"是否确认收货?" WithBtnCount:2];
    self.ormodel =model;

}
//申请退货
-(void)applyBackProduct:(OrderModel *)model
{
    ReturnGoodsVC *returnvc = [[ReturnGoodsVC alloc]init];
    returnvc.modalPresentationStyle = UIModalTransitionStyleCoverVertical;
    returnvc.block=^()
    {
        [self loaddata:_state andPage:@"1" withClic:YES];
    
    };
    returnvc.order_id = model.id_;
    returnvc.productCount = model.count;
    returnvc.isfromone = YES;
    [self presentViewController:returnvc animated:YES completion:nil];

}
//删除订单
-(void)delegetOrder:(OrderModel *)model
{
    [BackView addToview:self.view WithDeleget:self WithMessage:@"是否删除订单?" WithBtnCount:2];
    self.ormodel = model;
}
//查看原因
-(void)cleckReason:(OrderModel *)model
{

    [BackView addToview:self.view WithDeleget:self WithMessage:model.reject_order_reason WithBtnCount:1];
}
//chakanwuliu
-(void)loocForWuliu:(OrderModel *)model
{
    LogisticsVC *vc = [[LogisticsVC alloc]init];
    vc.order_id = model.id_;
    [self presentViewController:vc animated:YES completion:nil];
    
}
#pragma mark - cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return productCellHight;
    
}
#pragma mark - 点击警告框方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView == deletealert) {
        if (buttonIndex == 1) {
            [self deleteOrderWith:_state];
        }
    }else if (alertView == confirmalert){
        if (buttonIndex == 1) {
            [self confirmWithId:_state];
        }
    }
}
-(void)makeSureButtenClic:(UIButton *)btn withMessage:(NSString *)message
{
    if ([message isEqualToString:@"是否删除订单?"]) {
        if (btn.tag==0) {
            [self deleteOrderWith:self.ormodel.id_];
        }
    }else if ([message isEqualToString:@"是否确认收货?"])
    {
        if (btn.tag ==0) {
            [self confirmWithId:self.ormodel.id_];
        }
    }else if ([message isEqualToString:@"是否取消订单?"])
    {
        if (btn.tag==0) {
            [self cancelOrderWith:self.ormodel.id_];
        }
    }else if ([message isEqualToString:@"已确认收货"])
    {
        if (btn.tag==0) {
            [self loaddata:_state andPage:@"1"withClic:YES];
        }
    }

}
#pragma mark- 根据订单id删除订单
-(void)deleteOrderWith:(NSString *)orderId{
        NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
        [params setObject:orderId forKey:@"ids"];
        [WXDataService requestWithURL:@"mobile/order/deleteOrder.jhtml" params:params httpMethod:@"POST" block:^(id result, NSString *success, NSString *msg) {
            BOOL suc =[success boolValue];
            if (suc == 0 ) {
                UIAlertView *deleAlertView=[[UIAlertView alloc]initWithTitle:nil message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [deleAlertView show];
                return;
            }else if(suc == 1){
//                UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:nil message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//                [alertView show];
                
                [BackView addToview:self.view WithDeleget:self WithMessage:msg WithBtnCount:1];
                if (self.dataAry.count > 0){
                    [self.dataAry removeObjectAtIndex:deleBtnPath];
                }
                [maintableview reloadData];
            }
        }failblock:^(AFHTTPRequestOperation *operation, NSError *error) {
            
        }];
}
#pragma mark- 根据订单id取消订单
-(void)cancelOrderWith:(NSString *)orderId{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    [params setObject:orderId forKey:@"order_id_"];
    [WXDataService requestWithURL:@"mobile/agency/cancelOrder.jhtml" params:params httpMethod:@"POST" block:^(id result, NSString *success, NSString *msg) {
        BOOL suc =[success boolValue];
        if (suc == 0 ) {
            [BackView addToview:self.view WithDeleget:self WithMessage:@"订单取消失败" WithBtnCount:1];
            
            return;
        }else if(suc == 1){
            [BackView addToview:self.view WithDeleget:self WithMessage:@"订单取消成功" WithBtnCount:1];
            [self.dataAry removeObjectAtIndex:self.ormodel.tag];
            [maintableview reloadData];
        }
    }failblock:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
#pragma mark- 根据id确认收货
-(void)confirmWithId:(NSString *)ordrid{
    //发送确认收货的请求
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    [params setObject:ordrid forKey:@"oreder_id_"];
    [params setObject:@"14" forKey:@"state"];
    [WXDataService requestWithURL:@"mobile/agency/updateOrderState.jhtml" params:params httpMethod:@"POST" block:^(id result, NSString *success, NSString *msg) {
        BOOL suc =[success boolValue];
        if (suc == 0 ) {
            UIAlertView *deleAlertView=[[UIAlertView alloc]initWithTitle:nil message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [deleAlertView show];
            return;
        }else if(suc == 1){
            [BackView addToview:self.view WithDeleget:self WithMessage:@"已确认收货" WithBtnCount:1];
        }
    }failblock:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"错误原因:%@",error);
    }];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderDetailsVC *ordervc = [[OrderDetailsVC alloc]init];
    ordervc.deleget = self;
    ordervc.modalPresentationStyle =UIModalTransitionStyleCoverVertical;
    OrderModel *model = self.dataAry[indexPath.row];
    NSString *str = [NSString stringWithFormat:@"%@",model.state];
    if ([str isEqualToString:@"11"]) {
        ordervc.hidenWuliuView = YES;
    }else
    {
        ordervc.hidenWuliuView = NO;
    }
    ordervc.id_ = model.id_;
    
//    ordervc.id_ = [self.dataAry objectAtIndex:indexPath.row][@"id_"];
    [self presentViewController:ordervc animated:YES completion:nil];
}
#pragma mark - 点击头像
-(void)signalTapAction{
    [self dismissViewControllerAnimated:NO completion:nil];
    NSDictionary *dic = [NSDictionary dictionaryWithObject:@"AgentVC" forKey:@"vc"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ceshi" object:nil userInfo:dic];
}
-(void)pullTableViewDidTriggerLoadMore:(PullTableView *)pullTableView{
    page++;
    [self performSelector:@selector(refreshTable) withObject:nil afterDelay:2.0f];
    [self loaddata2:_state andPage:[NSString stringWithFormat:@"%i",page]];
}
- (void) refreshTable
{
    maintableview.pullTableIsLoadingMore = NO;
    maintableview.pullTableIsRefreshing = NO;
}

-(void)pullTableViewDidTriggerRefresh:(PullTableView *)pullTableView{
    page = 1;
    [self performSelector:@selector(refreshTable) withObject:nil afterDelay:2];
    [self loaddata:_state andPage:@"1"withClic:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark--订单详情的代理
-(void)shuaxin
{

    [self clickbtn:self.butten];
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
